package indi.zhifa.engine.test.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import indi.zhifa.core.auth.util.ITokenUtil;
import indi.zhifa.core.dataauth.handler.BaseAuthMetaObjectHandler;
import indi.zhifa.core.mpenhance.properties.MetaObjectHandlerProperty;
import indi.zhifa.engine.test.token.AuthObject;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.thymeleaf.spring6.context.SpringContextUtils;

@Component
public class AuthMetaObjectHandler extends BaseAuthMetaObjectHandler{

    final String enpIdStr = "enpId";
    final String enpCodeStr = "enpCode";
    final String enpNameStr = "enpName";


    @Override
    protected void otherInsertFill(MetaObject pMetaObject) {
        AuthObject authObject = mTokenUtil.getAuthObject();
        if(checkFieldNull(pMetaObject, enpIdStr)){
            this.strictInsertFill(pMetaObject,enpIdStr,()->authObject.getEnpId(),Long.class);
        }
        if(checkFieldNull(pMetaObject, enpCodeStr)){
            this.strictInsertFill(pMetaObject,enpCodeStr,()->authObject.getEnpCode(),String.class);
        }
        if(checkFieldNull(pMetaObject, enpNameStr)){
            this.strictInsertFill(pMetaObject,enpNameStr,()->authObject.getEnpName(),String.class);
        }
    }

    @Override
    protected void otherUpdateFill(MetaObject pMetaObject) {
    }
}
